package com.fuyao.cloud.asset.receivelist.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.log.annotation.SysLog;
import com.fuyao.cloud.asset.entity.receive.ReceiveList;
import com.fuyao.cloud.asset.receivelist.service.ReceiveListService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.fuyao.cloud.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 资产领用清单
 *
 * @author liyue
 * @date 2021-12-16 10:41:17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/receivelist" )
@Api(value = "receivelist", tags = "资产领用清单管理")
public class ReceiveListController {

    private final  ReceiveListService receiveListService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param receiveList 资产领用清单
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('receive_receive_view')" )
    public R getReceiveListPage(Page page, ReceiveList receiveList) {
        return R.ok(receiveListService.page(page, Wrappers.query(receiveList)));
    }


    /**
     * 通过id查询资产领用清单
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('receive_receive_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(receiveListService.getById(id));
    }

    /**
     * 新增资产领用清单
     * @param receiveList 资产领用清单
     * @return R
     */
    @ApiOperation(value = "新增资产领用清单", notes = "新增资产领用清单")
    @SysLog("新增资产领用清单" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('receive_receive_add')" )
    public R save(@RequestBody ReceiveList receiveList) {
        return R.ok(receiveListService.save(receiveList));
    }

    /**
     * 修改资产领用清单
     * @param receiveList 资产领用清单
     * @return R
     */
    @ApiOperation(value = "修改资产领用清单", notes = "修改资产领用清单")
    @SysLog("修改资产领用清单" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('receive_receive_edit')" )
    public R updateById(@RequestBody ReceiveList receiveList) {
        return R.ok(receiveListService.updateById(receiveList));
    }

    /**
     * 通过id删除资产领用清单
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除资产领用清单", notes = "通过id删除资产领用清单")
    @SysLog("通过id删除资产领用清单" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('receive_receive_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(receiveListService.removeById(id));
    }

	@ApiOperation(value = "通过ids删除资产领用清单", notes = "通过ids删除资产领用清单")
	@SysLog("通过ids删除资产领用清单" )
	@GetMapping("/delReceiveList" )
	@PreAuthorize("@pms.hasPermission('receive_receive_del')" )
	public R removeByIds(@RequestParam("ids") Long [] ids) {
		return R.ok(receiveListService.removeByIds(Arrays.asList(ids)));
	}

    /**
     * 导出excel 表格
     * @param receiveList 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('receive_receive_export')" )
    public List<ReceiveList> export(ReceiveList receiveList) {
        return receiveListService.list(Wrappers.query(receiveList));
    }
}
